#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

typedef struct TREENODE TreeNode;
typedef int Element;

struct TREENODE{
	Element elm;
	int 	meettime;
	TreeNode *left;
	TreeNode *right;
	TreeNode *father;
};

void printTree(TreeNode*);

_Bool firstNode=true;

int main(void){
	int nodes;
	scanf("%d",&nodes);
	TreeNode *root=(TreeNode*)malloc(sizeof(TreeNode));
	root->left=root->right=root->father=NULL;
	root->meettime=1;
	TreeNode *current=root;
	char buf[10];
	Element elm;
	for(int i=0;i< 2*nodes; i++){
		scanf("%s",buf);
		if( 0 == strcmp(buf,"Push") ){		//   Push condition
			scanf("%d",&elm);

			if( 1 == (current->meettime) ){
				TreeNode *new=malloc(sizeof(TreeNode));
				new->elm=elm;
				new->meettime=1;
				new->left=new->right=NULL;
				new->father=current;
				current->left=new;
				current=new;
			}
			else if( 2 == (current->meettime) ){
				TreeNode *new=malloc(sizeof(TreeNode));
				new->elm=elm;
				new->meettime=1;
				new->left=new->right=NULL;
				new->father=current;
				current->right=new;
				current=new;
			}
			//printf("|%s|%d|\n",buf,elm);
		}else{								//	 Pop condition
			(current->meettime)++;
			if( 2 == (current->meettime) ){
				//current->left=NULL;

			}else if ( 3 == (current->meettime) ){
				while( 3 == (current->meettime) ){
					current=current->father;
					(current->meettime)++;
				}
			}
			//printf("|%s|\n",buf);
		}
	}
	
	printTree( root->left );
	return 0;
}

void printTree(TreeNode *head){
/*
	_Bool firstNode=true;
	if( !(head->left) && !(head->right) ){
		if( firstNode ){
			printf("%d",head->elm);
			firstNode=false;
		}
		else	printf(" %d",head->elm);
	}
	printTree( head->left );
	if( firstNode ){
		printf("%d",head->lef
*/
	if( !head )
		return;
	printTree( head->left );
	printTree( head->right );
	if( firstNode ){
		printf("%d",head->elm);
		firstNode=false;
	}
	else
		printf(" %d",head->elm);
	return;
}
